package com.smscrypt;



import android.content.ContentValues;
import android.content.Context;
import android.database.Cursor;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;




public class DBHelper extends SQLiteOpenHelper {

	static final String dbName="SMSCrypt";
	static final String contactsTable="Contacts";
	static final String colID="id_contact";
	static final String colFirstName="firstname";
	static final String colLastName="lastname";
	static final String colPhoneNr="phone_nr";
	static final String colKey="crypt_key";
		
	public DBHelper(Context context) {
		super(context, dbName, null,33);
		
		// TODO Auto-generated constructor stub
	}

	@Override
	public void onCreate(SQLiteDatabase db) {
		// TODO Auto-generated method stub
		
		
		db.execSQL("CREATE TABLE "+contactsTable+" ("+colID+" INTEGER PRIMARY KEY AUTOINCREMENT, "+
				colFirstName+" TEXT, "+colLastName+" TEXT, "+colPhoneNr+" TEXT, "+colPhoneNr+" TEXT, "+colKey+" TEXT);");
		
		

		//Inserts pre-defined departments
		//InsertDepts(db);
		
	}

	@Override
	public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
		// TODO Auto-generated method stub
		
		db.execSQL("DROP TABLE IF EXISTS "+contactsTable);
		
		onCreate(db);
	}
	
	/* void AddEmployee(Employee emp)
	{
		 
		 
		 SQLiteDatabase db= this.getWritableDatabase();
		 
		
		ContentValues cv=new ContentValues();
		
		cv.put(colName, emp.getName());
		cv.put(colAge, emp.getAge());
		cv.put(colDept, emp.getDept());
		//cv.put(colDept,2);
		
		db.insert(contactsTable, colName, cv);
		db.close();
		
		
	}*/
	 
	 /*int getEmployeeCount()
	 {
		SQLiteDatabase db=this.getWritableDatabase();
		Cursor cur= db.rawQuery("Select * from "+contactsTable, null);
		int x= cur.getCount();
		cur.close();
		return x;
	 }*/
	 /* 
	 Cursor getAllEmployees()
	 {
		 SQLiteDatabase db=this.getWritableDatabase();
		 
		 
		 
		 //Cursor cur= db.rawQuery("Select "+colID+" as _id , "+colName+", "+colAge+" from "+contactsTable, new String [] {});
		 Cursor cur= db.rawQuery("SELECT * FROM "+viewEmps,null);
		 return cur;
		 
	 }*/
	 
	/* 
	 void InsertDepts(SQLiteDatabase db)
	 {
		 ContentValues cv=new ContentValues();
			cv.put(colDeptID, 1);
			cv.put(colDeptName, "Sales");
			db.insert(deptTable, colDeptID, cv);
			cv.put(colDeptID, 2);
			cv.put(colDeptName, "IT");
			db.insert(deptTable, colDeptID, cv);
			cv.put(colDeptID, 3);
			cv.put(colDeptName, "HR");
			db.insert(deptTable, colDeptID, cv);
			db.insert(deptTable, colDeptID, cv);
			
	 }*/
	 /* 
	 public String GetDept(int ID)
	 {
		 SQLiteDatabase db=this.getReadableDatabase();
		 
		 String[] params=new String[]{String.valueOf(ID)};
		 Cursor c=db.rawQuery("SELECT "+colDeptName+" FROM"+ deptTable+" WHERE "+colDeptID+"=?",params);
		 c.moveToFirst();
		 int index= c.getColumnIndex(colDeptName);
		 return c.getString(index);
	 }*/
	 /* 
	 public Cursor getEmpByDept(String Dept)
	 {
		 SQLiteDatabase db=this.getReadableDatabase();
		 String [] columns=new String[]{"_id",colName,colAge,colDeptName};
		 Cursor c=db.query(viewEmps, columns, colDeptName+"=?", new String[]{Dept}, null, null, null);
		 return c;
	 }*/
	 /* 
	 public int GetDeptID(String Dept)
	 {
		 SQLiteDatabase db=this.getReadableDatabase();
		 Cursor c=db.query(deptTable, new String[]{colDeptID+" as _id",colDeptName},colDeptName+"=?", new String[]{Dept}, null, null, null);
		 //Cursor c=db.rawQuery("SELECT "+colDeptID+" as _id FROM "+deptTable+" WHERE "+colDeptName+"=?", new String []{Dept});
		 c.moveToFirst();
		 return c.getInt(c.getColumnIndex("_id"));
		 
		 }*/
	 
	 /*public int UpdateEmp(Employee emp)
	 {
		 SQLiteDatabase db=this.getWritableDatabase();
		 ContentValues cv=new ContentValues();
		 cv.put(colName, emp.getName());
		 cv.put(colAge, emp.getAge());
		 cv.put(colDept, emp.getDept());
		 return db.update(contactsTable, cv, colID+"=?", new String []{String.valueOf(emp.getID())});
		 
	 }*/
	 
	 /*public void DeleteEmp(Employee emp)
	 {
		 SQLiteDatabase db=this.getWritableDatabase();
		 db.delete(contactsTable,colID+"=?", new String [] {String.valueOf(emp.getID())});
		 db.close();
		 
		
		
	 }*/

}
